/** *******************************************************************
 * Amfphp Redux
 * @author  Jonnie Spratley
 * @see jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.amfphpredux.model
{
	import com.adobe.cairngorm.model.IModelLocator;
	import com.jonniespratley.amfphpredux.vo.DatabaseVO;
	import com.jonniespratley.amfphpredux.vo.MethodVO;
	import com.jonniespratley.amfphpredux.vo.PreferenceVO;
	import com.jonniespratley.amfphpredux.vo.ServiceVO;
	import com.jonniespratley.amfphpredux.vo.TableVO;
	import com.jonniespratley.amfphpredux.vo.UserVO;
	
	import mx.collections.ArrayCollection;

	/**
	 * The Model Locator pattern is a singleton and was created purely 
	 * to be used with Flex/Air application development. In this case, 
	 * a singleton is a design pattern that allows for only one 
 	 * instance of the Model Locator to be present within your a
	 * application's memory. Any data that you think is required to live 
	 * in the application's state should be stored inside the Model Locator. 
	 * The Model Locator creates a central area where all the states 
	 * can be held in your Flex/Air application. This allows the view 
	 * components to bind to the model or state of the application 
	 * and keep everything up to date.
	 *
	 */
	
    [Bindable]
	public final class ModelLocator implements IModelLocator
	{
		/**
		 * Defines the Singleton instance of the Application ModelLocator
		 */
		private static var instance:ModelLocator;

		public function ModelLocator()
		{
			if( instance != null ) throw new Error( "Error: Singletons can only be instantiated via getInstance() method!" );

			ModelLocator.instance = this;
		}

		/**
		 * Returns the Singleton instance of the Application ModelLocator
		 */
		public static function getInstance():ModelLocator
		{
			if( instance == null )	instance = new ModelLocator();

			return instance;
		}

		// *********** Public Variables that our views are going to bind to ************** \\
		public var currentUser:UserVO;
		public var selectedPreference:PreferenceVO;
		
		public var serviceCollection:ArrayCollection;
		public var selectedService:ServiceVO;
		public var currentService:Object;
			
		public var methodsCollection:ArrayCollection;
		public var selectedMethod:MethodVO;		
		public var methods:Object;
		public var currentMethod:Object;
		public var methodDetails:String;

		public var databaseCollection:ArrayCollection;
		public var selectedDatabase:DatabaseVO;
		
		public var tableCollection:ArrayCollection;
		public var selectedTable:TableVO;
		
		public var userTableCollection:ArrayCollection;
		public var selectedUserTable:TableVO;
		
		public var userDatabaseCollection:ArrayCollection;
		public var selectedUserDatabase:DatabaseVO;
		

		// ***************** Public Static Variables for Work View States ************* \\
		public var workflowState:uint = 0;
		public var workflowDataManagerState:uint = 0;
		public var workflowServiceBrowserState:uint = 0;
		
		/* Workflow */
		public static const LOGIN_SCREEN:uint = 0;
		public static const MAIN_SCREEN:uint = 1;
		
		/* DataManager */
		public static const DATABASE_SCREEN:uint = 0;
		public static const DATABASE_LIST:uint = 1;
		
		/* Service Browser */
		public static const SERVICE_BROWSER_SCREEN:uint = 0;
		public static const SERVICE__BROWSER_CODE_SCREEN:uint = 1;
	}
}